home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap03 / howto04 / delphi10 / ufmgr13.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1995-10-25  |  31.3 KB  |  883 lines

  1. unit Ufmgr13;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl,
  8.    DRWSUtl1, DRWSUtl3;
  9.  
  10. type
  11.   TCCFileMgrForm = class(TForm)
  12.     Panel1: TPanel;
  13.     Panel2: TPanel;
  14.     BitBtn1: TBitBtn;
  15.     Panel3: TPanel;
  16.     Label1: TLabel;
  17.     BitBtn2: TBitBtn;
  18.     BitBtn3: TBitBtn;
  19.     BitBtn4: TBitBtn;
  20.     BitBtn5: TBitBtn;
  21.     BitBtn6: TBitBtn;
  22.     BitBtn7: TBitBtn;
  23.     OpenDialog1: TOpenDialog;
  24.     BitBtn8: TBitBtn;
  25.     BitBtn9: TBitBtn;
  26.     OpenDialog2: TOpenDialog;
  27.     BitBtn10: TBitBtn;
  28.     procedure FormResize(Sender: TObject);
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure BitBtn7Click(Sender: TObject);
  31.     procedure BitBtn1Click(Sender: TObject);
  32.     procedure BitBtn2Click(Sender: TObject);
  33.     procedure BitBtn3Click(Sender: TObject);
  34.     procedure BitBtn4Click(Sender: TObject);
  35.     procedure BitBtn5Click(Sender: TObject);
  36.     procedure FormPaint(Sender: TObject);
  37.     procedure BitBtn8Click(Sender: TObject);
  38.     procedure BitBtn9Click(Sender: TObject);
  39.     procedure BitBtn6Click(Sender: TObject);
  40.     procedure BitBtn1DragDrop(Sender, Source: TObject; X, Y: Integer);
  41.     procedure BitBtn1DragOver(Sender, Source: TObject; X, Y: Integer;
  42.       State: TDragState; var Accept: Boolean);
  43.     procedure BitBtn2DragDrop(Sender, Source: TObject; X, Y: Integer);
  44.     procedure BitBtn3DragDrop(Sender, Source: TObject; X, Y: Integer);
  45.     procedure BitBtn4DragDrop(Sender, Source: TObject; X, Y: Integer);
  46.     procedure BitBtn10Click(Sender: TObject);
  47.     procedure FormDestroy(Sender: TObject);
  48.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  49.       Shift: TShiftState);
  50.     procedure BitBtn9KeyDown(Sender: TObject; var Key: Word;
  51.       Shift: TShiftState);
  52.   private
  53.     { Private declarations }
  54.   public
  55.     { Public declarations }
  56.     DirectoryListBox1 : TDirectoryListBox;
  57.     FileListBox1 : TIconFileListBox;
  58.     ScrollBox1 : TFileIconPanelScrollbox;
  59.   end;
  60. var
  61.   CCFileMgrForm      : TCCFileMgrForm;
  62.   CurrentView        : Integer;  { This holds the current view setting      }
  63.  
  64. implementation
  65.  
  66. {$R *.DFM}
  67.  
  68. uses DDDFUnit,  { Include custom directory selection form }
  69.      CfmpfUn;   { Include custom options dialog           }
  70.  
  71. { Set up the resize to replace the icon buttons }
  72. procedure TCCFileMgrForm.FormResize(Sender: TObject);
  73. begin
  74.   { Send in the panel and global buttons list }
  75.   SpacePanelButtons( Panel2 );
  76. end;
  77.  
  78. { Delphi wrote this; use it to set everything up }
  79. procedure TCCFileMgrForm.FormCreate(Sender: TObject);
  80. var TheIconPanel : TFileIconPanel;
  81.     CurrentPath : String;
  82. begin
  83.   { Create the directory list box }
  84.   DirectoryListBox1 := TDirectoryListBox.Create( Panel1 );
  85.   DirectoryListBox1.Parent := Panel1;
  86.   DirectoryListBox1.Visible := true;
  87.   DirectoryListbox1.Top := 17;
  88.   DirectoryListbox1.Left := 0;
  89.   DirectoryListbox1.Height := Panel1.Height - 32;
  90.   DirectoryListbox1.Width := 0;
  91.   { Create the file list box }
  92.   FileListBox1 := TIconFileListBox.Create( Panel1 );
  93.   FileListBox1.Parent := Panel1;
  94.   FileListbox1.Top := 17;
  95.   FileListbox1.Left := 146;
  96.   FileListbox1.Height := Panel1.Height - 32;
  97.   FileListbox1.Width := 0;
  98.   FileListBox1.Visible := true;
  99.   FileListBox1.ShowGlyphs := true;
  100.   FileListBox1.MultiSelect := true;
  101.   FileListBox1.DragMode := dmAutomatic;
  102.   { Set intercomponent interactions }
  103.   DirectoryListBox1.FileList := FileListbox1;
  104.   DirectoryListBox1.DirLabel := Label1;
  105.   { Create the scrollbox }
  106.   ScrollBox1 := TFileIconPanelScrollBox.Create( Panel1 );
  107.   ScrollBox1.Parent := Panel1;
  108.   ScrollBox1.align := alClient;
  109.   ScrollBox1.Left := 0;
  110.   ScrollBox1.Top := 0;
  111.   ScrollBox1.Width := Panel1.Width - 32;
  112.   ScrollBox1.Height := Panel1.Height - 32;
  113.   ScrollBox1.IconsNeedRefreshing := false;
  114.   ScrollBox1.TheStoredHandle := Self.Handle;
  115.   ScrollBox1.TheParentForm := Self;
  116.   { Get the current directory with 0 parameter }
  117.   GetDir( 0 , CurrentPath );
  118.   { Set the display caption }
  119.   Label1.Caption := CurrentPath;
  120.   { Add a trailing \ if not root }
  121.   CurrentPath := ScrollBox1.TheFWB.ForceTrailingBackSlash( CurrentPath );
  122.   { Get the icons display using scrollbox1 }
  123.   ScrollBox1.GetIconsForEntireDirectory( CurrentPath );
  124.   { Set the Icon View as default }
  125.   CurrentView := 1;
  126.   { Start the FIP IOManager }
  127.   if not assigned( TheIOManager ) then
  128.   begin
  129.     TheIOManager := TIOManager.Create( Self );
  130.     TheIOManager.Parent := Self;
  131.   end;
  132. end;
  133.  
  134. { Delphi wrote this; use it to close the application }
  135. procedure TCCFileMgrForm.BitBtn7Click(Sender: TObject);
  136. begin
  137.   Close;
  138. end;
  139.  
  140. { Delphi wrote this use it to perform a copy on all selected files }
  141. procedure TCCFileMgrForm.BitBtn1Click(Sender: TObject);
  142. var ThePosition  : Integer;       { Loop counter   }
  143.     CurrentName ,                 { Holds work name}
  144.     TheOldString : String;        { Holds Dir      }
  145.     finished     : Boolean;       { Loop control   }
  146.     WorkingDir   : String;        { Holds mod wd   }
  147.     TargetDir    : String;        { target of op   }
  148.     TheResult    : Integer;       { Modal res hold }
  149. begin
  150.   { Get current directory and save it for later }
  151.   GetDir( 0 , TheOldString );
  152.   { Check for need to add trailing \ }
  153.   WorkingDir := TheOldString;
  154.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  155.   { Display the Windows-based directory input form }
  156.   TheResult := DestDDForm.ShowModal;
  157.   { If not cancelled do the copy }
  158.   if TheResult = mrOK then
  159.   begin
  160.     { Get the target directory with \ OK }
  161.     TargetDir := DestDDForm.GetTargetDirectory;
  162.     { Show the hourglass to indicate waiting }
  163.     Screen.Cursor := crHourGlass;
  164.     { Setup to get all selections }
  165.     ThePosition := 1;
  166.     finished := false;
  167.     while not finished do
  168.     begin
  169.       { Call generic file getting routine based on current view}
  170.       case CurrentView of
  171.         1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  172.              ThePosition );
  173.         2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  174.              ThePosition );
  175.       end;
  176.       { If returns blank string out of selections so exit }
  177.       if CurrentName = '' then finished := true else
  178.       begin
  179.         { If a directory signal error }
  180.         if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  181.         begin
  182.           if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' + TargetDir
  183.            +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  184.           begin
  185.             ScrollBox1.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  186.              TargetDir );
  187.           end;
  188.         end
  189.         else
  190.         begin
  191.           Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  192.         end;
  193.       end;
  194.     end;
  195.     { Reset to normal cursor }
  196.     Screen.Cursor := crDefault;
  197.   end;
  198.   { Reset to the original directory }
  199.   ChDir( TheOldString );
  200. end;
  201.  
  202. { Delphi wrote this, use it to move files which are selected }
  203. procedure TCCFileMgrForm.BitBtn2Click(Sender: TObject);
  204. var ThePosition  : Integer;       { Loop counter   }
  205.     CurrentName ,                 { Holds work name}
  206.     TheOldString : String;        { Holds Dir      }
  207.     finished     : Boolean;       { Loop control   }
  208.     WorkingDir   : String;        { Holds mod wd   }
  209.     TargetDir    : String;        { target of op   }
  210.     TheResult    : Integer;       { Modal res hold }
  211. begin
  212.   { Get current directory and save it for later }
  213.   GetDir( 0 , TheOldString );
  214.   { Check for need to add trailing \ }
  215.   WorkingDir := TheOldString;
  216.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  217.   { Display the Windows-based directory input form }
  218.   TheResult := DestDDForm.ShowModal;
  219.   { If not cancelled do the copy }
  220.   if TheResult = mrOK then
  221.   begin
  222.     { Get the target directory with \ OK }
  223.     TargetDir := DestDDForm.GetTargetDirectory;
  224.     { Show the hourglass to indicate waiting }
  225.     Screen.Cursor := crHourGlass;
  226.     { Set up to get all current selections }
  227.     ThePosition := 1;
  228.     finished := false;
  229.     while not finished do
  230.     begin
  231.       { Call generic file getting routine based on current view}
  232.       case CurrentView of
  233.         1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  234.              ThePosition );
  235.         2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  236.              ThePosition );
  237.       end;
  238.       { If returns blank string then out of selections }
  239.       if CurrentName = '' then finished := true else
  240.       begin
  241.         { If a directory signal error }
  242.         if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  243.         begin
  244.           if MessageDlg( 'Move Directory ' + CurrentName + ' to ' + TargetDir +
  245.            '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  246.             ScrollBox1.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  247.              TargetDir );
  248.         end
  249.         else
  250.         begin
  251.           Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  252.         end;
  253.       end;
  254.       { Reset to normal cursor }
  255.       Screen.Cursor := crDefault;
  256.     end;
  257.   end;
  258.   { Reset to the original directory }
  259.   ChDir( TheOldString );
  260.   if CurrentView = 1 then { Reset icon display if in view }
  261.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  262. end;
  263.  
  264. { Delphi wrote this, use it to delete files which are selected }
  265. procedure TCCFileMgrForm.BitBtn3Click(Sender: TObject);
  266. var ThePosition  : Integer;       { Loop counter   }
  267.     CurrentName ,                 { Holds work name}
  268.     TheOldString : String;        { Holds Dir      }
  269.     finished     : Boolean;       { Loop control   }
  270.     WorkingDir   : String;        { Holds mod wd   }
  271. begin
  272.   { Get current directory and save it for later }
  273.   GetDir( 0 , TheOldString );
  274.   { Check for need to add trailing \ }
  275.   WorkingDir := TheOldString;
  276.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  277.   { Set up to do loop for selected files }
  278.   ThePosition := 1;
  279.   finished := false;
  280.   while not finished do
  281.   begin
  282.     { Call generic file getting routine based on current view}
  283.     case CurrentView of
  284.       1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  285.            ThePosition );
  286.       2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  287.            ThePosition );
  288.     end;
  289.     { if returns blank string out of selections }
  290.     if CurrentName = '' then finished := true else
  291.     begin
  292.       { If its a directory signal error }
  293.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  294.       begin
  295.         if MessageDlg( 'Delete Directory ' + CurrentName + '?' , mtConfirmation,
  296.          mbYesNoCancel , 0 ) = mrYes then
  297.         begin
  298.           ScrollBox1.TheFWB.RecursivelyDeleteDirectory( CurrentName );
  299.           Scrollbox1.TheFWB.RemoveDirectory( Currentname );
  300.         end;
  301.       end
  302.       else
  303.       begin
  304.         { Otherwise get confirmation message and if OKed delete file }
  305.         if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  306.          mbYesNoCancel , 0 ) = mrYes then
  307.         begin
  308.           ScrollBox1.TheFWB.DeleteTheFile( Currentname );
  309.         end;
  310.       end;
  311.     end;
  312.   end;
  313.   if CurrentView = 1 then { Reset icon display if in view }
  314.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  315. end;
  316.  
  317. { Delphi wrote this; use it to rename selected files }
  318. procedure TCCFileMgrForm.BitBtn4Click(Sender: TObject);
  319. var ThePosition  : Integer;       { Loop counter   }
  320.     CurrentName ,                 { Holds work name}
  321.     TheOldString : String;        { Holds Dir      }
  322.     finished     : Boolean;       { Loop control   }
  323.     WorkingDir   : String;        { Holds mod wd   }
  324. begin
  325.   { Get current directory for later }
  326.   GetDir( 0 , TheOldString );
  327.   { Check for need to add trailing \ }
  328.   WorkingDir := TheOldString;
  329.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  330.   { Set up to do loop for selected files }
  331.   ThePosition := 1;
  332.   finished := false;
  333.   while not finished do
  334.   begin
  335.     { Call generic file getting routine based on current view}
  336.     case CurrentView of
  337.       1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  338.            ThePosition );
  339.       2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  340.            ThePosition );
  341.     end;
  342.     { If returns blank string then out of selections }
  343.     if CurrentName = '' then finished := true else
  344.     begin
  345.       { Otherwise set up the opendialog with filename and caption }
  346.       OpenDialog1.Filename := ExtractFilename( CurrentName );
  347.       { Use this to prevent error from changing directories }
  348.       OpenDialog1.Options := [ofNoChangeDir];
  349.       OpenDialog1.Title := 'Rename File';
  350.       { If not cancelled then do rename or signal error }
  351.       if OpenDialog1.Execute then
  352.       begin
  353.         ScrollBox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  354.       end;
  355.     end;
  356.   end;
  357.   if CurrentView = 1 then { Reset icon display if in view }
  358.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  359. end;
  360.  
  361. { Delphi wrote this; use it to make a new directory under current one }
  362. procedure TCCFileMgrForm.BitBtn5Click(Sender: TObject);
  363. begin
  364.   { Set up the dialog to get the new directory name }
  365.   OpenDialog2.FileName := '*.*';
  366.   OpenDialog2.Title := 'Enter Directory Name';
  367.   if OpenDialog1.Execute then
  368.   begin
  369.     { If not cancelled make new directory }
  370.     Scrollbox1.TheFWB.CreateNewDirectory( OpenDialog1.Filename );
  371.   end;
  372.   if CurrentView = 1 then { Reset icon display if in view }
  373.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  374. end;
  375.  
  376. { Delphi wrote this; use it to handle refreshing the scrollbox }
  377. procedure TCCFileMgrForm.FormPaint(Sender: TObject);
  378. var CurrentDirectory : String; { Get current dir }
  379. begin
  380.   { If updated, do refresh }
  381.   if ScrollBox1.IconsNeedRefreshing then
  382.   begin
  383.     Scrollbox1.ClearTheFIPs;
  384.     ScrollBox1.IconsNeedRefreshing := false;
  385.     GetDir( 0 , CurrentDirectory );
  386.     { Force trailing backslash }
  387.     CurrentDirectory := ScrollBox1.TheFWB.ForceTrailingBackSlash(
  388.      CurrentDirectory );
  389.     { Set the label to the new directory }
  390.     Label1.Caption := UpperCase( CurrentDirectory );
  391.     { Do the update }
  392.     ScrollBox1.GetIconsForEntireDirectory( CurrentDirectory );
  393.   end;
  394. end;
  395.  
  396. { Delphi wrote this; use it to reset the current view Icons/List }
  397. procedure TCCFileMgrForm.BitBtn8Click(Sender: TObject);
  398. var TheOldString : String; { Use to get current directory }
  399. begin
  400.   { Reset currentview }
  401.   if CurrentView = 1 then CurrentView := 2 else
  402.    CurrentView := 1;
  403.   { either show the windows boxes or the scrollbox }
  404.   case CurrentView of
  405.     1 : begin
  406.           { Make the listboxes invisible by changing align and width }
  407.           FileListBox1.Visible := false;
  408.           FileListBox1.Align := alNone;
  409.           FileListBox1.Width := 0;
  410.           DirectoryListBox1.Visible := false;
  411.           DirectoryListBox1.align := alNone;
  412.           DirectoryListBox1.Width := 0;
  413.           { Keep them from getting mouse clicks }
  414.           FileListBox1.Enabled := false;
  415.           DirectoryListBox1.Enabled := false;
  416.           { Have the scrollbox get mouse and be seen  by resetting align/wid}
  417.           Scrollbox1.align := alClient;
  418.           Scrollbox1.width := Panel1.Width - 32;
  419.           ScrollBox1.Enabled := true;
  420.           { Tell the scrollbox to repaint itself just in case }
  421.           ScrollBox1.Update;
  422.         end;
  423.     2 : begin
  424.           { Make the listboxes visible by resetting align and width}
  425.           FileListBox1.Visible := true;
  426.           DirectoryListBox1.Visible := true;
  427.           DirectoryListBox1.width := 145;
  428.           DirectoryListBox1.align := alLeft;
  429.           FileListBox1.align := alClient;
  430.           FileListBox1.Width := Panel1.Width - 32 - DirectoryListBox1.Width;
  431.           { Have them getting mouse clicks }
  432.           FileListBox1.Enabled := true;
  433.           DirectoryListBox1.Enabled := true;
  434.           { Have the scrollbox not get mouse and not be seen via align/width}
  435.           ScrollBox1.Enabled := false;
  436.           ScrollBox1.Visible := false;
  437.           ScrollBox1.align := alNone;
  438.           ScrollBox1.Width := 0;
  439.         end;
  440.   end;
  441.   Invalidate;
  442. end;
  443.  
  444. { Delphi wrote this; use it to do a file search display }
  445. procedure TCCFileMgrForm.BitBtn9Click(Sender: TObject);
  446. var CurrentDirectory : String; { Holds current directory }
  447. begin
  448.   { Set up and run the search dialog }
  449.   OpenDialog2.FileName := '*.*';
  450.   { if not cancelled do the search }
  451.   if OpenDialog2.Execute then
  452.   begin
  453.     { Get current directory }
  454.     GetDir( 0 , CurrentDirectory );
  455.     { Force trailing backslash }
  456.     CurrentDirectory :=
  457.      ScrollBox1.TheFWB.ForceTrailingBackSlash( CurrentDirectory );
  458.     { display recursive search results }
  459.     GlobalAbortFlag := false;
  460.     Scrollbox1.DisplayRecursiveSearchResults(
  461.      CurrentDirectory + OpenDialog2.Filename );
  462.     Label1.Caption := 'Search Results for ' + CurrentDirectory +
  463.      OpenDialog2.FileName;
  464.   end;
  465. end;
  466.  
  467. { Delphi wrote this; use it to set a file's properties }
  468. procedure TCCFileMgrForm.BitBtn6Click(Sender: TObject);
  469. var ThePosition  : Integer;       { Loop counter   }
  470.     CurrentName ,                 { Holds work name}
  471.     TheOldString : String;        { Holds Dir      }
  472.     finished     : Boolean;       { Loop control   }
  473.     WorkingDir   : String;        { Holds mod wd   }
  474. begin
  475.   { Get current directory for later }
  476.   GetDir( 0 , TheOldString );
  477.   ThePosition := 1;
  478.   { Check for need to add trailing \ }
  479.   Workingdir := TheOldString;
  480.   WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDIr );
  481.   { Call generic file getting routine based on current view}
  482.   case CurrentView of
  483.     1 : CurrentName := ScrollBox1.GetNextSelection( WorkingDir ,
  484.          ThePosition );
  485.     2 : CurrentName := FileListBox1.GetNextSelection( WorkingDir ,
  486.          ThePosition );
  487.   end;
  488.   { If nothing selected then abort (gets ..!) }
  489.   if CurrentName = '' then
  490.   begin
  491.     MessageDlg( 'No File Selected!' , mtError , [mbOK] , 0 );
  492.     exit;
  493.   end
  494.   else
  495.   begin
  496.     { Otherwise set up the properties form and show it }
  497.     CCFMPropsForm.WorkingFileName := CurrentName;
  498.     CCFMPropsForm.ThePosition := ThePosition;
  499.     CCFMPropsForm.BitBtn4.Enabled := true;
  500.     CCFMPropsForm.Initialize;
  501.     CCFMPropsForm.ShowModal;
  502.   end;
  503.   if CurrentView = 1 then { Reset icon display if in view }
  504.    ScrollBox1.Update else FileListBox1.Update; { Otherwise update the FLB }
  505. end;
  506.  
  507. { Delphi wrote this; use it to drag and drop files for copying }
  508. procedure TCCFileMgrForm.BitBtn1DragDrop(Sender, Source: TObject; X,
  509.   Y: Integer);
  510. var CurrentName ,                 { Holds work name}
  511.     WorkingDir ,
  512.     TheOldString : String;        { Holds Dir      }
  513.     TargetDir    : String;        { target of op   }
  514.     TheResult    : Integer;       { Modal res hold }
  515.     Counter_1    : Integer;
  516. begin
  517.   { Make sure source is indeed a FileIconPanel }
  518.   if Source is TIconFileListbox then
  519.   begin
  520.     with Source as TIconFileListBox do
  521.     begin
  522.      { Get current directory and save it for later }
  523.      GetDir( 0 , TheOldString );
  524.      WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( TheOldString );
  525.      { Display the Windows-based directory input form }
  526.      TheResult := DestDDForm.ShowModal;
  527.      { If not cancelled do the copy }
  528.      if TheResult = mrOK then
  529.      begin
  530.        for Counter_1 := 1 to Items.Count do
  531.        begin
  532.          if Selected[ Counter_1 - 1 ] then
  533.          begin
  534.             CurrentName := WorkingDIr + Items[ Counter_1 - 1 ];
  535.             { Get the target directory with \ OK }
  536.             TargetDir := DestDDForm.GetTargetDirectory;
  537.             { If a directory signal and do recursive operation }
  538.             if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  539.             begin
  540.               if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' + TargetDir
  541.                +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  542.               begin
  543.                 ScrollBox1.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  544.                  TargetDir );
  545.               end;
  546.             end
  547.             else
  548.             begin
  549.               { Do the copy }
  550.               Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  551.             end;
  552.             { Reset to the original directory }
  553.             ChDir( TheOldString );
  554.           end;
  555.         end;
  556.       end;
  557.     end;
  558.     FileListBox1.Update;
  559.     exit;
  560.   end;
  561.   if TheIOManager.WasSHIFTPressed then
  562.   begin
  563.     BitBtn1Click( Source );
  564.     exit;
  565.   end;
  566.   with Source as TFileIconPanel do
  567.   begin
  568.     { Get current directory and save it for later }
  569.     GetDir( 0 , TheOldString );
  570.     { Display the Windows-based directory input form }
  571.     TheResult := DestDDForm.ShowModal;
  572.     { If not cancelled do the copy }
  573.     if TheResult = mrOK then
  574.     begin
  575.       CurrentName := FTheName;
  576.       { Get the target directory with \ OK }
  577.       TargetDir := DestDDForm.GetTargetDirectory;
  578.       { If a directory signal and do recursive operation }
  579.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  580.       begin
  581.         if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' + TargetDir
  582.          +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  583.         begin
  584.           ScrollBox1.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  585.            TargetDir );
  586.         end;
  587.       end
  588.       else
  589.       begin
  590.         { Do the copy }
  591.         Scrollbox1.TheFWB.CopyTheFile( CurrentName , TargetDir );
  592.       end;
  593.       { Reset to the original directory }
  594.       ChDir( TheOldString );
  595.     end;
  596.   end;
  597. end;
  598.  
  599. { Delphi wrote this; use it to generically OK DnD from FIPs }
  600. procedure TCCFileMgrForm.BitBtn1DragOver(Sender, Source: TObject; X,
  601.   Y: Integer; State: TDragState; var Accept: Boolean);
  602. begin
  603.   { Only accept from FileIconPanel components }
  604.   if ( Source is TFileIconPanel ) or
  605.      ( Source is TIconFileListBox ) then Accept := true else Accept := false;
  606. end;
  607.  
  608. { Delphi wrote this; use it to accept Drag and Drop moving }
  609. procedure TCCFileMgrForm.BitBtn2DragDrop(Sender, Source: TObject; X,
  610.   Y: Integer);
  611. var CurrentName ,                 { Holds work name}
  612.     WorkingDir ,
  613.     TheOldString : String;        { Holds Dir      }
  614.     TargetDir    : String;        { target of op   }
  615.     TheResult       : Integer;    { Modal res hold }
  616.     Counter_1   : Integer;
  617. begin
  618.   { Make sure source is indeed a FileIconPanel }
  619.   if Source is TIconFileListbox then
  620.   begin
  621.     with Source as TIconFileListBox do
  622.     begin
  623.       { Get current directory and save it for later }
  624.       GetDir( 0 , TheOldString );
  625.       WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( TheOldString );
  626.       { Display the Windows-based directory input form }
  627.       TheResult := DestDDForm.ShowModal;
  628.       for Counter_1 := 1 to Items.Count do
  629.       begin
  630.         if Selected[ Counter_1 - 1 ] then
  631.         begin
  632.           { If not cancelled do the copy }
  633.           if TheResult = mrOK then
  634.           begin
  635.             CurrentName := WorkingDir + Items[ Counter_1 - 1 ];
  636.             { Get the target directory with \ OK }
  637.             TargetDir := DestDDForm.GetTargetDirectory;
  638.             { If a directory signal and do recursive operation }
  639.             if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  640.             begin
  641.               if MessageDlg( 'Move Directory ' + CurrentName + ' to ' + TargetDir
  642.                +'?', mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  643.               begin
  644.                 ScrollBox1.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  645.                  TargetDir );
  646.               end;
  647.             end
  648.             else
  649.             begin
  650.               { Do the copy }
  651.               Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  652.             end;
  653.             { Reset to the original directory }
  654.             ChDir( TheOldString );
  655.           end;
  656.         end;
  657.       end;
  658.     end;
  659.     FileListBox1.Update;
  660.     exit;
  661.   end;
  662.   if TheIOManager.WasSHIFTPressed then
  663.   begin
  664.     BitBtn2Click( Source );
  665.     exit;
  666.   end;
  667.   with Source as TFileIconPanel do
  668.   begin
  669.     { Get current directory and save it for later }
  670.     GetDir( 0 , TheOldString );
  671.     { Display the Windows-based directory input form }
  672.     TheResult := DestDDForm.ShowModal;
  673.     { If not cancelled do the copy }
  674.     if TheResult = mrOK then
  675.     begin
  676.       { Get the target directory with \ OK }
  677.       TargetDir := DestDDForm.GetTargetDirectory;
  678.       { If Copyfile returns false an error occurred }
  679.       CurrentName := FTheName;
  680.       { If a directory signal and do recursion }
  681.       if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  682.       begin
  683.         if MessageDlg( 'Move Directory ' + CurrentName + ' to ' + TargetDir +
  684.          '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  685.           ScrollBox1.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  686.            TargetDir );
  687.       end
  688.       else
  689.       begin  { Do the move }
  690.         Scrollbox1.TheFWB.MoveTheFile( CurrentName , TargetDir );
  691.         ChDir( TheOldString );
  692.       end;
  693.       { Refresh display }
  694.       ScrollBox1.Update;
  695.     end;
  696.   end;
  697. end;
  698.  
  699. { Delphi wrote this; use it to do drag and drop deletes }
  700. procedure TCCFileMgrForm.BitBtn3DragDrop(Sender, Source: TObject; X,
  701.   Y: Integer);
  702. var WorkingDir ,
  703.     CurrentName : String;  { Holds work name}
  704.     Counter_1   : Integer;
  705. begin
  706.   { Make sure source is indeed a FileIconPanel }
  707.   if Source is TIconFileListbox then
  708.   begin
  709.     with Source as TIconFileListBox do
  710.     begin
  711.       GetDir( 0 , WorkingDir );
  712.       WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  713.       for Counter_1 := 1 to Items.Count do
  714.       begin
  715.         if Selected[ Counter_1 - 1 ] then
  716.         begin
  717.           CurrentName := WorkingDir + Items[ Counter_1 - 1 ];
  718.           { If a directory signal and do recursive operation }
  719.           if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  720.           begin
  721.             if MessageDlg( 'Delete Directory ' + CurrentName +'?',
  722.              mtConfirmation , mbYesNoCancel , 0 ) = mryes then
  723.             begin
  724.               ScrollBox1.TheFWB.RecursivelyDeleteDirectory( CurrentName );
  725.               Scrollbox1.TheFWB.RemoveDirectory( CurrentName );
  726.             end;
  727.           end
  728.           else
  729.           begin
  730.             if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  731.              mbYesNoCancel , 0 ) = mrYes then
  732.             begin
  733.               Scrollbox1.TheFWB.DeleteTheFile( CurrentName );
  734.             end;
  735.           end;
  736.         end;
  737.       end;
  738.     end;
  739.     FileListBox1.Update;
  740.     exit;
  741.   end;
  742.   if TheIOManager.WasSHIFTPressed then
  743.   begin
  744.     BitBtn3Click( Source );
  745.     exit;
  746.   end;
  747.   with Source as TFileIconPanel do
  748.   begin
  749.     CurrentName := FTheName;
  750.     { If its a directory signal and do recursive delete }
  751.     if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  752.     begin
  753.       if MessageDlg( 'Delete Directory ' + CurrentName + '?' , mtConfirmation ,
  754.        mbYesNoCancel , 0 ) = mrYes then
  755.       begin
  756.         Scrollbox1.TheFWB.RecursivelyDeleteDirectory( CurrentName );
  757.         Scrollbox1.TheFWB.RemoveDirectory( CurrentName );
  758.       end;
  759.     end
  760.     else
  761.     begin
  762.       { Otherwise get confirmation message and if OKed delete file }
  763.       if MessageDlg( 'Delete file ' + CurrentName + '?', mtConfirmation ,
  764.        mbYesNoCancel , 0 ) = mrYes then
  765.       begin
  766.         Scrollbox1.TheFWB.DeleteTheFile( CurrentName );
  767.       end;
  768.     end;
  769.     { Refresh Display }
  770.     Scrollbox1.Update;
  771.   end;
  772. end;
  773.  
  774. { Delphi wrote this; use it to do drag and drop renames }
  775. procedure TCCFileMgrForm.BitBtn4DragDrop(Sender, Source: TObject; X,
  776.   Y: Integer);
  777. var WorkingDir ,
  778.     CurrentName : String;  { Holds work name}
  779.     Counter_1   : Integer;
  780. begin
  781.   { Make sure source is indeed a FileIconPanel }
  782.   if Source is TIconFileListbox then
  783.   begin
  784.     with Source as TIconFileListBox do
  785.     begin
  786.       GetDir( 0 , WorkingDir );
  787.       WorkingDir := ScrollBox1.TheFWB.ForceTrailingBackSlash( WorkingDir );
  788.       for Counter_1 := 1 to Items.Count do
  789.       begin
  790.         if Selected[ Counter_1 - 1 ] then
  791.         begin
  792.           CurrentName := WorkingDir + Items[ Counter_1 - 1 ];
  793.           { Otherwise set up the opendialog with filename and caption }
  794.           OpenDialog2.Filename := ExtractFilename( CurrentName );
  795.           { Use this to prevent error from changing directories }
  796.           OpenDialog2.Options := [ofNoChangeDir];
  797.           OpenDialog2.Title := 'Rename File';
  798.           { If not cancelled then do rename or signal error }
  799.           if OpenDialog2.Execute then
  800.           begin
  801.             Scrollbox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  802.           end;
  803.         end;
  804.       end;
  805.     end;
  806.     FileListBox1.Update;
  807.     exit;
  808.   end;
  809.   if TheIOManager.WasSHIFTPressed then
  810.   begin
  811.     BitBtn4Click( Source );
  812.     exit;
  813.   end;
  814.   with Source as TFileIconPanel do
  815.   begin
  816.     CurrentName := FTheName;
  817.     { If a directory signal error }
  818.     { Otherwise set up the opendialog with filename and caption }
  819.     OpenDialog2.Filename := ExtractFilename( CurrentName );
  820.     { Use this to prevent error from changing directories }
  821.     OpenDialog2.Options := [ofNoChangeDir];
  822.     OpenDialog2.Title := 'Rename File';
  823.     { If not cancelled then do rename or signal error }
  824.     if OpenDialog2.Execute then
  825.     begin
  826.       Scrollbox1.TheFWB.RenameTheFile( CurrentName , OpenDialog1.Filename );
  827.     end;
  828.     { Refresh the display }
  829.     ScrollBox1.Update;
  830.   end;
  831. end;
  832.  
  833. procedure TCCFileMgrForm.BitBtn10Click(Sender: TObject);
  834. var TheCCFMForm : TCCFileMgrForm;
  835. begin
  836.   TheCCFMForm := TCCFileMgrForm.Create( Application );
  837.   TheCCFMForm.Show;
  838. end;
  839.  
  840. procedure TCCFileMgrForm.FormDestroy(Sender: TObject);
  841. begin
  842.   { Release the IO Manager }
  843.   if assigned( TheIOManager) then
  844.   begin
  845.     TheIOManager.Free;
  846.     TheIOManager := nil;
  847.   end;
  848. end;
  849.  
  850. procedure TCCFileMgrForm.FormKeyDown(Sender: TObject; var Key: Word;
  851.   Shift: TShiftState);
  852. begin
  853.   case Key of
  854.     VK_F1 : TheIOManager.OnF1Pressed( Sender , Key , Shift );
  855.     VK_F2 : TheIOManager.OnF2Pressed( Sender , Key , Shift );
  856.     VK_F3 : TheIOManager.OnF3Pressed( Sender , Key , Shift );
  857.     VK_F4 : TheIOManager.OnF4Pressed( Sender , Key , Shift );
  858.     VK_F5 : TheIOManager.OnF5Pressed( Sender , Key , Shift );
  859.     VK_F6 : TheIOManager.OnF6Pressed( Sender , Key , Shift );
  860.     VK_F7 : TheIOManager.OnF7Pressed( Sender , Key , Shift );
  861.     VK_F8 : TheIOManager.OnF8Pressed( Sender , Key , Shift );
  862.     VK_F9 : TheIOManager.OnF9Pressed( Sender , Key , Shift );
  863.     VK_F10 : TheIOManager.OnF10Pressed( Sender , Key , Shift );
  864.     VK_F11 : TheIOManager.OnF11Pressed( Sender , Key , Shift );
  865.     VK_F12 : TheIOManager.OnF12Pressed( Sender , Key , Shift );
  866.   end;
  867. end;
  868.  
  869. { Delphi wrote this; use it to respond to control-break presses }
  870. procedure TCCFileMgrForm.BitBtn9KeyDown(Sender: TObject; var Key: Word;
  871.   Shift: TShiftState);
  872. begin
  873.   case Key of
  874.     VK_CANCEL : begin  {Put up a message dlg and if OK set abort flag}
  875.                   if MessageDlg( 'Control Break Pressed! Abort Search?',
  876.                    mtConfirmation,mbYesNoCancel,0) = mrYes
  877.                     then GlobalAbortFlag := true;
  878.                 end;
  879.   end;
  880. end;
  881.  
  882. end.
  883.